﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">

    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
    <script type="text/javascript">
        //刷新ztree
        function parentReload() {
            if (null != "${MSG}" && 'change' == "${MSG}") {
                parent.location.href = "<%=basePath%>classify/listAllClassify.do?id=0";
            } else {
                //什么也不干
            }
        }

        parentReload();
    </script>
</head>
<body class="no-skin">

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">

                        <table id="dynamic-table" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th class='center'>分类ID</th>
                                <th class='center'>分类名称</th>
                                <th class='center'>所属上级分类ID</th>
                                <th class='center'>分类图标</th>
                                <th class='center' style="width: 120px;">操作</th>
                            </tr>
                            </thead>

                            <tbody>
                            <c:choose>
                                <c:when test="${not empty classifyList}">
                                    <c:forEach items="${classifyList}" var="classify" varStatus="vs">
                                        <tr>
                                            <td class='center'>
                                                <i class="">${classify.id }</i>

                                            </td>
                                            <td>
                                                <a href="javascript:goSonClassify('${classify.id}')">${classify.name}</a>
                                            </td>
                                            <td>
                                                    ${classify.parentid == '0'? '根分类': classify.parentid}
                                            </td>
                                            <c:if test="${classify.icoImg != null}">
                                                <td class="center"><a href="${classify.icoImg }" target='_blank'><img
                                                        src="${classify.icoImg }" height="60px;"/></a></td>
                                            </c:if>
                                            <c:if test="${classify.icoImg == null}">
                                                <td class="center"></td>
                                            </c:if>
                                            <td class='center'>
                                                <c:if test="${QX.edit != 1 && QX.del != 1 }">
                                                    <span class="label label-large label-grey arrowed-in-right arrowed-in"><i
                                                            class="ace-icon fa fa-lock" title="无权限"></i></span>
                                                </c:if>
                                                <div class="hidden-sm hidden-xs action-buttons">
                                                    <c:if test="${QX.edit == 1 }">
                                                        <a class="green"
                                                           href="javascript:editClassify('${classify.id}');">
                                                            <i class="ace-icon fa fa-pencil-square-o bigger-130"
                                                               title="修改"></i>
                                                        </a>
                                                    </c:if>
                                                    <c:if test="${QX.del == 1 }">
                                                        <a class="red" href="javascript:delClassify('${classify.id}');">
                                                            <i class="ace-icon fa fa-trash-o bigger-130" title="删除"></i>
                                                        </a>
                                                    </c:if>
                                                </div>

                                                <div class="hidden-md hidden-lg">
                                                    <div class="inline pos-rel">
                                                        <button
                                                                class="btn btn-minier btn-yellow dropdown-toggle"
                                                                data-toggle="dropdown" data-position="auto">
                                                            <i
                                                                    class="ace-icon fa fa-caret-down icon-only bigger-120"></i>
                                                        </button>

                                                        <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                                            <c:if test="${QX.edit == 1 }">
                                                                <li><a href="javascript:editClassify('${classify.id}');"
                                                                       class="tooltip-success" data-rel="tooltip"
                                                                       title="Edit">
															<span class="green">
																<i class="ace-icon fa fa-pencil-square-o bigger-120"
                                                                   title="修改"></i>
															</span>
                                                                </a></li>
                                                            </c:if>
                                                            <c:if test="${QX.del == 1 }">
                                                                <li><a href="javascript:delClassify('${classify.id}');"
                                                                       class="tooltip-error" data-rel="tooltip"
                                                                       title="Delete">
															<span class="red"> <i
                                                                    class="ace-icon fa fa-trash-o bigger-120"
                                                                    title="删除"></i>
															</span>
                                                                </a></li>
                                                            </c:if>
                                                        </ul>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <tr>
                                        <td colspan="100" class='center'>没有相关数据</td>
                                    </tr>
                                </c:otherwise>
                            </c:choose>
                            </tbody>
                        </table>

                        <div>
                            &nbsp;&nbsp;
                            <c:if test="${QX.add == 1 }"><a class="btn btn-sm btn-success"
                                                            onclick="addClassify('${id}');">新增</a></c:if>
                            <c:if test="${null != pd.id && pd.id != '0'}">
                                <a class="btn btn-sm btn-success" onclick="goSonClassify('${pd.parentid}');">返回</a>
                            </c:if>
                        </div>

                    </div>
                    <!-- /.col -->
                </div>

                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->

    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

</div>
<!-- /.main-container -->

<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- 删除时确认窗口 -->
<script src="static/ace/js/bootbox.js"></script>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>

<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(document).ready(function () {
        top.hangge();
    });

    //去此ID下子菜单列表
    function goSonClassify(id) {
        top.jzts();
        window.location.href = "<%=basePath%>classify.do?id=" + id;
    };

    //新增菜单
    function addClassify(id) {
        top.jzts();
        window.location.href = "<%=basePath%>classify/toAdd.do?id=" + id;
    };

    //编辑菜单
    function editClassify(id) {
        top.jzts();
        window.location.href = "<%=basePath%>classify/toEdit.do?id=" + id;
    };

    //删除
    function delClassify(id) {
        bootbox.confirm("确定要删除此分类吗?", function (result) {
            if (result) {
                var url = "<%=basePath%>classify/delete.do?id=" + id + "&guid=" + new Date().getTime();
                top.jzts();
                $.get(url, function (data) {
                    if ("success" == data.result) {
                        parent.location.href = "<%=basePath%>classify/listAllClassify.do?id=" +${id};
                    } else if ("false" == data.result) {
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>删除失败,请先删除子分类!</span>",
                            buttons:
                                {
                                    "button":
                                        {
                                            "label": "确定",
                                            "className": "btn-sm btn-success"
                                        }
                                }
                        });
                    } else {
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>删除失败,请先删除跟分类下商品!</span>",
                            buttons:
                                {
                                    "button":
                                        {
                                            "label": "确定",
                                            "className": "btn-sm btn-success"
                                        }
                                }
                        });
                    }
                });
            }
        });
    }

    //弹出关联品牌
    function associatedBrand(id, name) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "关联品牌";
        diag.URL = '<%=basePath%>classify/associatedBrand.do?id=' + id + '&name=' + encodeURI(encodeURI(name));
        diag.Width = 900;
        diag.Height = 600;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('associatedBrand').style.display == 'none') {
                nextPage('${page.currentPage}');
            }
            diag.close();
        };
        diag.show();
    }

    function nextPage(page) {
        top.jzts();
        if (true && document.forms[0]) {
            var url = document.forms[0].getAttribute("action");
            if (url.indexOf('?') > -1) {
                url += "&currentPage=";
            }
            else {
                url += "?currentPage=";
            }
            url = url + page + "&showCount=10";
            document.forms[0].action = url;
            document.forms[0].submit();
        } else {
            var url = document.location + '';
            if (url.indexOf('?') > -1) {
                if (url.indexOf('currentPage') > -1) {
                    var reg = /currentPage=\d*/g;
                    url = url.replace(reg, 'currentPage=');
                } else {
                    url += "&currentPage=";
                }
            } else {
                url += "?currentPage=";
            }
            url = url + page + "&showCount=10";
            document.location = url;
        }
    }
</script>


</body>
</html>